<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>资金流水</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">资金流水列表</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-row" style="margin-bottom:1%">
                    <div class="layui-form" style="float:right;">
                        <div class="layui-form-item" style="margin:0;">
                            <label class="layui-form-label">流水ID</label>
                        <div class="layui-input-inline">
                            <input type="text" name="id" id="id" placeholder="流水ID" autocomplete="off" class="layui-input">
                        </div>
                        <button id="search" class="layui-btn" data-type="reload">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        </div>
                    </div>
                </div>
                <table id="zjlsList" lay-filter="zjlsList"></table>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="payBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看</a>
</script>

<script>
     layui.use(['table','util','form','admin','form','layer'], function(){
        var table = layui.table
        ,$ = layui.$
        ,form = layui.form
            ,view =layui.view,
            admin =layui.admin,
            layer =layui.layer
        ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        table.render({
            elem: '#zjlsList'
            ,url: layui.setter.baseUrl + '/account/history_list'
            ,where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            ,id: 'tableReload'
            ,cols: [[
                {field:'id', title: '流水ID', sort: true }
                ,{field: 'amount',title: '金额',templet: '<div>{{d.amount/100}}</div>'}
                ,{field: 'balance',title: '账户余额',templet: '<div>{{d.balance/100}}</div>'}
                ,{field: 'fundDirection',title: '资金变动方向',templet: '<div>{{d.fundDirection == 1?"加款":"减款"}}</div>'}
                ,{field: 'isCompleteSett',title: '是否完成结算',templet: '<div>{{d.isCompleteSett == 1?"已完成":"未完成"}}</div>'}
                ,{field: 'bizType',title: '业务类型',templet: '<div>{{d.bizType == 1?"消费":""}}</div>'}
                ,{field:'createTime',  title: '创建时间', templet: '<div>{{ layui.util.toDateString(d.createTime) }}</div>' }
                ,{field:'edite', title: '操作', toolbar: '#payBar' }
            ]]
            ,page: true
            ,skin: 'line'
        });

         table.on('tool(zjlsList)', function(obj){
             var data = obj.data;
             if(obj.event === 'detail'){
                 var curdid =data.id;
                 admin.req({
                     type: 'get',
                     url: layui.setter.baseUrl + '/account/history_get',
                     data: {
                         id : curdid
                     },
                     error: function(err){
                         layer.alert(JSON.stringify(err.field), {
                             title: '错误提示'
                         })
                     },
                     success: function(res){
                         if(res.code == 0){
                             data=res.data;
                             admin.popup({
                                 title: '基本信息'
                                 , area: ['730px', '505px']
                                 , id: 'LAY-popup-content-detail'
                                 , success: function (layero, index) {
                                     view(this.id).render('account/history/historydetail').done(function () {
                                         form.render(null, 'layuiadmin-app-form-list');

                                         var body =layer.getChildFrame('body',index);
                                         body.find('#email').val(data.email);
                                         form.val("layuiadmin-app-form-list",{

                                             "mchId":data.mchId,
                                             "name":data.name,
                                             "id" :data.id,
                                             "fundDirection":data.fundDirection==1?"加款":"减款"

                                         })
                                         $('#amount').val(res.data.amount/100);
                                         $('#balance').val(res.data.balance/100);
                                         $('#isAllowSett').val(res.data.isAllowSett ==1?"允许":"不允许");
                                         $('#isCompleteSett').val(res.data.isCompleteSett ==1?"已完成":"未完成");
                                         $('#orderId').val(res.data.orderId);
                                         $('#channelOrderNo').val(res.data.channelOrderNo);
                                         $('#bizType').val(res.data.bizType ==1?"消费":"");
                                         $('#riskDay').val(res.data.riskDay);
                                         if(res.data.createTime != "" && res.data.createTime != null) {
                                             $('#createTime').val(layui.util.toDateString(res.data.createTime));
                                         }
                                         if(res.data.updateTime != "" && res.data.updateTime != null) {
                                             $('#updateTime').val(layui.util.toDateString(res.data.updateTime));
                                         }
                                         form.render();
                                     });
                                 }
                             });

                         }else{
                             layer.alert({title:'请求成功，但是获取数据失败'});
                         }
                     }
                 })
             }
         });

        // 搜索
        var $ = layui.$, active = {
            reload: function(){
                var id = $('#id').val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        id : id
                    }
                });
            }
        };
        $('#search').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        // 渲染表单
        form.render();


     })
</script>